<?php

namespace Fluency\Metadata;

use Fluency\Utils\AnnotationReader;

/**
 * @package Fluency\Metadata
 * @author  Ignas Rudaitis
 * @version 2.0.0
 */
class AnnotatedActionMetadata implements ActionMetadata
{
    const FILTERS_ANNOTATION = "Filters";
    const VIEW_ANNOTATION = "View";
    const INTERNAL_ANNOTATION = "Internal";

    private $annotations;

    public function __construct(AnnotationReader $annotations)
    {
        $this->annotations = $annotations;
    }

    public function getAttribute($name)
    {
        return $this->annotations->getAnnotation($name);
    }

    public function getFilterParameters($filter)
    {
        return $this->annotations->getSubAnnotations(array(static::FILTERS_ANNOTATION, $filter));
    }

    public function getFilters()
    {
        return (array) $this->annotations->getAnnotation(static::FILTERS_ANNOTATION);
    }

    public function getViewParameters($format)
    {
        return $this->annotations->getSubAnnotations(array(static::VIEW_ANNOTATION, $format));
    }

    public function getView($format)
    {
        return $this->annotations->getAnnotation(array(static::VIEW_ANNOTATION, $format));
    }

    public function isInternal()
    {
        return (boolean) $this->annotations->getAnnotation(static::INTERNAL_ANNOTATION);
    }
}